Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details-toggle Catalyst element to improve accessibility of Details component #3292

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ktravers
Copy link
Contributor

@ktravers ktravers commented Jan 26, 2025

Authors: Please fill out this form carefully and completely.

Reviewers: By approving this Pull Request you are approving the code change, as well as its deployment and mitigation plans.
Please read this description carefully. If you feel there is anything unclear or missing, please ask for updates.

What are you trying to accomplish?

This PR adds a new Catalyst element, details-toggle, to the Details component in order to ensure that when a Details component is toggled open/closed, its aria attributes are updated as expected by default.

Previously, aria-expanded and aria-label attributes were not included at all, which made it difficult for screen reader users interact with a rendered Details component, given there was no indication what would happen when the component was activated.

Note

For GitHub staff reviewers: these changes have been upstreamed from dotcom. See https://github.com/github/github/pull/357658.

Screenshots

Screen.recording.Details.component.aria.attribute.changes.mov
Screenshot Primer docs - Details

Integration

Yes, but only for github/github. When this version of @primer/view-components is released, we can deprecate the Catalyst element added in https://github.com/github/github/pull/357658. Note that this change isn't technically required, in that nothing will break if we delay or even skip removing the gh/gh component. It's purely code cleanup, removing duped/unnecessary code to improve general maintainability.

List the issues that this change affects.

Related to https://github.com/github/accessibility-audits/issues/10012

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

What approach did you choose and why?

I followed existing conventions for this codebase and created a Catalyst component for updating the aria attributes when the details component is toggled open/closed.

Re: visual changes -- These are intentional. They're present because I added reasonable default aria label values to the Primer::Alpha::Dropdown component, which renders Primer::Beta::Details. So Dropdown will also benefit from these accessibility improvements.

Anything you want to highlight for special attention from reviewers?

Nothing in particular.

Accessibility

  • Fixes axe scan violation - This change fixes an existing axe scan violation.
  • No new axe scan violation - This change does not introduce any new axe scan violations.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

Copy link

changeset-bot bot commented Jan 26, 2025

🦋 Changeset detected

Latest commit: ba55e1d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ktravers ktravers force-pushed the ktravers/upstream-details-element branch from e222165 to 66761f1 Compare January 27, 2025 03:27
@ktravers ktravers self-assigned this Jan 27, 2025
@ktravers ktravers marked this pull request as ready for review January 27, 2025 04:07
@ktravers ktravers requested a review from a team as a code owner January 27, 2025 04:07
Copy link
Contributor

github-actions bot commented Jan 27, 2025

⚠️ Visual or ARIA snapshot differences found

Our visual and ARIA snapshot tests found UI differences. Please review the differences by viewing the files changed tab to ensure that the changes were intentional.

Review differences

@github-actions github-actions bot requested a review from a team as a code owner January 27, 2025 04:49
@github-actions github-actions bot requested a review from tbenning January 27, 2025 04:49
@ktravers
Copy link
Contributor Author

Taking this back to draft while I investigate visual differences.

@ktravers ktravers marked this pull request as draft January 27, 2025 04:58
Copy link
Contributor

@camertron camertron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! 🎉 What would you think about adding some system tests for this that check the aria labels when the elements are open and closed?

Comment on lines +111 to +116
assert_selector("details.dropdown") do
assert_selector("summary.btn", text: "Button")
assert_selector("summary.btn[aria-label='Open me']")
assert_selector("summary[data-aria-label-open='Close me']")
assert_selector("summary[data-aria-label-closed='Open me']")
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think assert_selector with an implicit receiver searches the entire page. Calling it on the yielded element instead should have the nesting effect you're after:

Suggested change
assert_selector("details.dropdown") do
assert_selector("summary.btn", text: "Button")
assert_selector("summary.btn[aria-label='Open me']")
assert_selector("summary[data-aria-label-open='Close me']")
assert_selector("summary[data-aria-label-closed='Open me']")
end
assert_selector("details.dropdown") do |dropdown|
dropdown.assert_selector("summary.btn", text: "Button")
dropdown.assert_selector("summary.btn[aria-label='Open me']")
dropdown.assert_selector("summary[data-aria-label-open='Close me']")
dropdown.assert_selector("summary[data-aria-label-closed='Open me']")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants